package com.lmqb.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.lmqb.bean.SysUser;
import com.lmqb.entry.MenuTitle;
import com.lmqb.page.AreaPager;
import com.lmqb.page.CouponPager;
import com.lmqb.page.EmailLogPager;
import com.lmqb.page.SchoolPager;
import com.lmqb.page.SysBlackPager;
import com.lmqb.service.DataService;
import com.lmqb.service.JiaoYanService;

@Controller
public class DataController extends BaseController{

	@Autowired
	private JiaoYanService jiaoYanService;
	
	@Autowired
	private DataService dataService;
	
	//黑名单列表
	@RequestMapping(value="sysBlack.html",method=RequestMethod.GET)
	public String toSysBlack(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,SysBlackPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(SysBlackPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			SysBlackPager blackPager=dataService.selectBlackPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, blackPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("数据中心");
			menuTitle.setMenu("黑名单库");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "sysBlackList";
	}
	
	//学校列表
	@RequestMapping(value="school.html",method=RequestMethod.GET)
	public String toSchool(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,SchoolPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(SchoolPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			SchoolPager blackPager=dataService.selectSchoolPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, blackPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("数据中心");
			menuTitle.setMenu("学校列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "schoolList";
	}
	
	//地区列表
	@RequestMapping(value="area.html",method=RequestMethod.GET)
	public String toArea(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,AreaPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(AreaPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			AreaPager blackPager=dataService.selectAreaPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, blackPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("数据中心");
			menuTitle.setMenu("省市区列表");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "areaList";
	}
	

	//启用区的状态
	@RequestMapping("updateStatusByarea")
	public String updateStatusByarea(String areaNo){
		dataService.updateStatusByarea(areaNo);
		return "redirect:area.html";
	}
	
	//禁用区的状态
	@RequestMapping("updateStatusByarea1")
	public String updateStatusByarea1(String areaNo){
		dataService.updateStatusByarea1(areaNo);
		return "redirect:area.html";
	}
	

	//跳转到批量修改页面
	@RequestMapping(value="toupdateArea.html",method=RequestMethod.GET)
	public String toupdateArea(HttpSession session,HttpServletRequest request,
			HttpServletResponse response){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("省市区列表");
			menuTitle.setMenu("批量修改省市区");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "updateArea";
	}
	
	@RequestMapping(value="updateArea.html")
	public String updateArea(String address){
	dataService.updateArea(address);

		return "redirect:area.html";
	}
	
	
	
	
	
	

	//优惠券
	@RequestMapping(value="coupon.html",method=RequestMethod.GET)
	public String toCoupon(HttpSession session,HttpServletRequest request,
			HttpServletResponse response,CouponPager pagerModel){
		try{
			SysUser sysUser=(SysUser)session.getAttribute(memberAdmin);
			if(sysUser==null){
				return "login";
			}
			pagerModel=(CouponPager) jiaoYanService.pagerModelFormat(pagerModel);
			setIfEmpty(pagerModel);
			CouponPager couponPager=dataService.selectCouponPager(pagerModel);
			setIfEndty(pagerModel);
			request.setAttribute(pager, couponPager);
			MenuTitle menuTitle=new MenuTitle();
			menuTitle.setParent("活动");
			menuTitle.setMenu("优惠券");
			session.setAttribute(menuTitleF, menuTitle);
		}catch(Exception e){
			e.printStackTrace();
		}
		
		return "couponList";
	}
	
	
}
